﻿using Com.Qiniu.ShopErp.App.Device.Print;
using Mengsk.ProxyDelivery.App.Device;
using Mengsk.ProxyDelivery.App.Domain;
using Mengsk.ProxyDelivery.Service;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace Mengsk.ProxyDelivery.App.UI.Order
{
    /// <summary>
    /// OrderChangePrint.xaml 的交互逻辑
    /// </summary>
    public partial class OrderChangePrint : Window
    {

        private VendorService vs = ServiceContainer.GetService<VendorService>();

        public OrderChangePrint()
        {
            InitializeComponent();
        }

        private void btnPrint_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                string id = this.tbId.Text.Trim();
                string vendor = this.tbVendor.Text.Trim();
                string goods = this.tbGoods.Text.Trim();

                if (string.IsNullOrWhiteSpace(id) || string.IsNullOrWhiteSpace(vendor) || string.IsNullOrWhiteSpace(goods))
                {
                    throw new Exception("打印信息不能为空");
                }
                var vendors = vs.GetByName(vendor);
                if (vendors == null || vendors.Count < 1)
                {
                    throw new Exception("未查询到厂家");
                }

                if (vendors.Count > 1)
                {
                    throw new Exception("查询到的厂家数量不为0");
                }

                var gi = new OrderReturnPrintInfo { Door = VendorService.FormatVendorDoor(vendors[0].MarketAddress), Id = id, Stocking = goods, Vendor = VendorService.FormatVendorName(vendors[0].Name) };
                PrintDevice.Print(gi);
                this.DialogResult = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}
